package com.itheima.d7_interface_demo.practice;

import java.util.ArrayList;

public class StudentServiceImpl2 implements StudentService{
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("-----全班学生信息如下-----");

        int boy = 0;
        int girl = 0;

        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            System.out.println("姓名：" + student.getName() + "，性别" + student.getSex() + "，成绩：" + student.getScore());
            if(student.getSex() == '男'){
                boy++;
            }else {
                girl++;
            }
        }
        System.out.println("男生人数是：" + boy + "，女生人数是" + girl);
        System.out.println("班级总人数为：" + students.size());
        System.out.println("--------------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double sum = 0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();

        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            sum += student.getScore();
            //最高分
            if (student.getScore() > max) {
                max = student.getScore();
            }
            //最低分
            if (student.getScore() < min) {
                min = student.getScore();
            }
        }
        double average = (sum - max - min) / (students.size() - 2);
        System.out.println("学生的最高分是：" + max);
        System.out.println("学生的最低分是：" + min);
        System.out.println("平均分：" + average);
    }
}
